package com.ruoyi.project.module.group.controller;

import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.module.application.domain.Application;
import com.ruoyi.project.module.application.mapper.ApplicationMapper;
import com.ruoyi.project.module.application.service.IApplicationService;
import com.ruoyi.project.module.group.service.IGroupService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * com.ruoyi.project.module.group.controller.ReleaseController
 * <br>
 *
 * @author 蒋カイセキ    Japan-Tokyo  19-4-15 下午7:00<br>
 * ブログ http://www.shoukaiseki.top/<br>
 * E-メール jiang28555@Gmail.com<br>
 **/
@Controller
@RequestMapping("/module/group")
public class ReleaseController extends BaseController {

    private String prefix = "module/group";

    @Autowired
    private IGroupService groupService;

    @Resource
    private ApplicationMapper applicationMapper;

    /**
     * 发布配置组
     */
    @RequiresPermissions("module:group:release")
    @GetMapping( "/release/{uniqueId}")
    public String release(@PathVariable("uniqueId") Long uniqueId, ModelMap mmap)
    {

        mmap.put("configGroupId",uniqueId);

        return prefix+"/releaseSelect";
    }

    /**
     * 查询配置应用管理列表
     */
    @RequiresPermissions("module:application:list")
    @PostMapping("/release/list")
    @ResponseBody
    public TableDataInfo list(Long configGroupId,String searchValue)
    {
        List<Application> list = applicationMapper.getReleaseApplicationList(configGroupId,searchValue);
        return getDataTable(list);
    }

    /**
     * 发布配置组
     */
    @RequiresPermissions("module:group:release")
    @PostMapping( "/release/toApplication")
    @ResponseBody
    public AjaxResult releaseToApplication(Long configGroupId,Long[] appIds)
    {
        groupService.release(configGroupId, appIds);
        return success();
    }
}
